package com.ruoyi.web.controller.customer;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.customer.domain.UserCustomerInfo;
import com.ruoyi.customer.service.IUserCustomerInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户 - 客户信息Controller
 *
 * @author ruoyi
 * @date 2019-09-28
 */
@Controller
@RequestMapping("/customer/baseinfo")
public class UserCustomerInfoController extends BaseController
{
    private String prefix = "customer/baseinfo";

    @Autowired
    private IUserCustomerInfoService userCustomerInfoService;

    @RequiresPermissions("customer:baseinfo:view")
    @GetMapping()
    public String baseinfo()
    {
        return prefix + "/baseinfo";
    }

    /**
     * 查询用户 - 客户信息列表
     */
    @RequiresPermissions("customer:baseinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserCustomerInfo userCustomerInfo)
    {
        startPage();
        userCustomerInfo.setUserId(ShiroUtils.getUserId());
        List<UserCustomerInfo> list = userCustomerInfoService.selectUserCustomerInfoList(userCustomerInfo);
        return getDataTable(list);
    }

    /**
     * 导出用户 - 客户信息列表
     */
    @RequiresPermissions("customer:baseinfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserCustomerInfo userCustomerInfo)
    {
        userCustomerInfo.setUserId(ShiroUtils.getUserId());
        List<UserCustomerInfo> list = userCustomerInfoService.selectUserCustomerInfoList(userCustomerInfo);
        ExcelUtil<UserCustomerInfo> util = new ExcelUtil<UserCustomerInfo>(UserCustomerInfo.class);
        return util.exportExcel(list, "baseinfo");
    }

    /**
     * 新增用户 - 客户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户 - 客户信息
     */
    @RequiresPermissions("customer:baseinfo:add")
    @Log(title = "用户 - 客户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserCustomerInfo userCustomerInfo)
    {
        userCustomerInfo.setUserId(ShiroUtils.getUserId());
        return toAjax(userCustomerInfoService.insertUserCustomerInfo(userCustomerInfo));
    }

    /**
     * 修改用户 - 客户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserCustomerInfo userCustomerInfo = userCustomerInfoService.selectUserCustomerInfoById(id);
        mmap.put("userCustomerInfo", userCustomerInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户 - 客户信息
     */
    @RequiresPermissions("customer:baseinfo:edit")
    @Log(title = "用户 - 客户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserCustomerInfo userCustomerInfo)
    {
        return toAjax(userCustomerInfoService.updateUserCustomerInfo(userCustomerInfo));
    }

    /**
     * 删除用户 - 客户信息
     */
    @RequiresPermissions("customer:baseinfo:remove")
    @Log(title = "用户 - 客户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userCustomerInfoService.deleteUserCustomerInfoByIds(ids));
    }
}